<?php

namespace app\api\controller\hire;

use app\api\model\hire\Hire as HireModel;
use app\api\controller\Controller;
use app\api\model\hire\Category as CategoryModel;
use app\api\model\paper\RecordQuestion as RecordQuestionModel;
use app\api\model\examination\Log as ExaminationLogModel;
use app\api\model\examination\ExaminationUserAward as ExaminationUserAwardModel;
use app\api\model\settings\Setting as SettingModel;
use app\api\model\examination\ExaminationAward as ExaminationAwardModel;
use app\api\model\page\Ab as AbModel;

/**
 * 招聘控制器
 */
class Hire extends Controller
{

    /*
     * 排行榜
     * */
    public function paperRanking(){
        $model = new ExaminationLogModel;
        $data = $this->postData();
        $list=$model->getList($data);
        $my_ranling=$model->getMyList($data,$this->getUser());
        //获取配置
        $config = SettingModel::getItem('rankingsettlement');
        $arr=getEndtime($config['status']);
        $rule=array_merge($config,$arr);
        return $this->renderSuccess('', compact('list','my_ranling','rule'));
    }

    //奖品详情
    public function awardDetails(){
        $model = new ExaminationAwardModel;
        $data = $this->getData();
        $list=$model->details($data);
        return $this->renderSuccess('', compact('list'));
    }

    //我的奖品
    public function myAward(){
        $model = new ExaminationUserAwardModel;
        $data = $this->getData();
        $list=$model->getList($data,$this->getUser());
        return $this->renderSuccess('', compact('list'));
    }
    /*
     * 奖品列表
     * */
    public function Award(){
        $model = new ExaminationAwardModel;
        $list=$model->getList();
        return $this->renderSuccess('', compact('list'));
    }



    /**
     * 招聘列表
     */
    public function list()
    {
        // 获取列表数据
        $model = new HireModel;
        $data = $this->postData();
        $data['course_type'] = 1;
        $list = $model->getList($data);
        $category = CategoryModel::getList();
        $abmodel = new AbModel();
        $ab=$abmodel->getIndex(['status'=>1],10);
        return $this->renderSuccess('', compact('list','category','ab'));
    }

    /**
     * 教务列表
     */
    public function lists()
    {
        // 获取列表数据
        $model = new HireModel;
        $data = $this->postData();
        $data['course_type'] = 2;
        $list = $model->getList($data);
        return $this->renderSuccess('', compact('list'));
    }

    /**
     * 招聘详情
     */
    public function detail($hire_id)
    {
        // 获取列表数据
        $model = new HireModel;
        $detail = $model->getDetail($hire_id, $this->getUser(false));
        return $this->renderSuccess('', compact('detail'));
    }

    /**
     * 招聘章节详情
     */
    public function sectionDetail()
    {
        $user = $this->getUser(false);
        // 获取列表数据
        $model = new CourseSectionModel;
        $detail = $model->getDetail($this->postData(), $user);
        if ($detail) {
            return $this->renderSuccess('', compact('detail'));
        } else {
            return $this->renderError($model->getError() ?: '查看失败');
        }
    }
}